package by.gravity.drive_track.utils;

import java.lang.reflect.Field;

import android.graphics.Point;
import android.os.IBinder;
import android.util.Log;
import android.util.Property;
import android.view.View;

import com.google.android.gms.maps.model.Marker;

public class MapUtils {

	private static int number = 0;

	public static Point getMargerPosiont(Marker marker) {
		try {
			number = 0;
			getField(marker, marker, "cX", "b", "c", "h", "n", "b", "e", "a", "e");
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// catch (IllegalAccessException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		return null;
	}

	private static final void getField(Object object, Object zObject, String... params) throws NoSuchFieldException,
			IllegalArgumentException, IllegalAccessException {
		Log.e("test", ("number =" + number + params[number]));
		object.getClass().getFields();
		object.getClass().getDeclaredFields();
		Field field = getInnerField(object, params[number]);
		field.setAccessible(true);
		if (number == 8) {
			Field field2 = object.getClass().getField("TRANSLATION_X");
			field2.setAccessible(true);
			Property view = (Property) field2.get(object);
			view.get(object);
		}
		Object value = getInnFieldValue(object, field);
		number++;
		if (number <= params.length) {
			getField(value, zObject, params);
		}
	}

	private static final Field getInnerField(Object object, String paramName) throws NoSuchFieldException {
		return object.getClass().getDeclaredField(paramName);

	}

	private static final Object getInnFieldValue(Object input, Field filed) throws IllegalArgumentException,
			IllegalAccessException {
		return filed.get(input);
	}
}
